package com.itheima.controller;

import com.itheima.config.SpringConfig;
import com.itheima.domain.Account;
import com.itheima.service.AccountService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class App {
    public static void main(String[] args) {
        ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
        AccountService accountService = (AccountService) ctx.getBean("accountService");

        // 查询所有
        List<Account> all = accountService.findAll();
        for (Account account : all) {
            System.out.println(account);
        }

        /*// 根据id查询
        Account id = accountService.findById(1);
        System.out.println(id);*/

        /*// 添加
        Account account = new Account();
        account.setName("罗童");
        account.setMoney(100000.0);
        accountService.save(account);*/

        /*// 修改
        Account account = new Account(1, "徐圳益", 100.0);
        accountService.update(account);*/

        // 删除
        accountService.delete(3);
    }
}
